home *** CD-ROM | disk | FTP | other *** search
- { pabort.pas -- Test printer abort function and dialog }
-
- program PAbort;
-
- {$R pbitmap.res} { Uses PBitMap's resource file }
-
- uses WinTypes, WinProcs, WObjects, UBitmap, UAbort;
-
- const
-
- fileName = 'c:\tpw\owldemos\nolimits.bmp';
-
- id_Menu = 100; { Menu resource ID }
- cm_Print = 101; { Menu:Print command ID }
- cm_Quit = 102; { Menu:Exit command ID }
-
- type
-
- PAbortApplication = object(TApplication)
- procedure InitMainWindow; virtual;
- end;
-
- PPAbortWindow = ^PAbortWindow;
- PAbortWindow = object(TWindow)
- Bitmap: HBitmap; { Handle to bitmap in memory }
- Width, Height: LongInt; { Size of bitmap image }
- constructor Init(AParent: PWindowsObject; ATitle: PChar);
- destructor Done; virtual;
- procedure SetupWindow; virtual;
- function CanClose: Boolean; virtual;
- procedure AdjustScroller;
- procedure Paint(PaintDC: HDC;
- var PaintInfo: TPaintStruct); virtual;
- procedure WMSize(var Msg: TMessage);
- virtual wm_First + wm_Size;
- procedure CMPrint(var Msg: TMessage);
- virtual cm_First + cm_Print;
- procedure CMQuit(var Msg: TMessage);
- virtual cm_First + cm_Quit;
- end;
-
-
- { PAbortApplication }
-
- {- Initialize PAbortApplication object's window }
- procedure PAbortApplication.InitMainWindow;
- begin
- MainWindow := New(PPAbortWindow, Init(nil, 'PAbort'))
- end;
-
-
- { PAbortWindow }
-
- {- Construct PAbortWindow object }
- constructor PAbortWindow.Init(AParent: PWindowsObject; ATitle: PChar);
- begin
- TWindow.Init(AParent, ATitle);
- with Attr do
- begin
- X := 10; Y := 10; W := 500; H := 300;
- Menu := LoadMenu(HInstance, PChar(id_Menu));
- Style := Style or ws_VScroll or ws_HScroll;
- end;
- Scroller := New(PScroller, Init(@Self, 1, 1, 200, 200))
- end;
-
- {- Destroy PAbortWindow }
- destructor PAbortWindow.Done;
- begin
- if Bitmap <> 0 then DeleteObject(Bitmap);
- TWindow.Done
- end;
-
- {- Load and display bitmap }
- procedure PAbortWindow.SetupWindow;
- begin
- TWindow.SetupWindow;
- Bitmap := LoadBitmap(fileName, HWindow, Width, Height);
- if Bitmap = 0 then
- begin
- MessageBox(HWindow, 'File not found', 'Error',
- mb_IconExclamation or mb_ok);
- Halt
- end
- end;
-
- {- Return true if okay to close window }
- function PAbortWindow.CanClose: Boolean;
- begin
- CanClose := not Printing
- end;
-
- {- Adjust scroll bar ranges after window size changes }
- procedure PAbortWindow.AdjustScroller;
- var
- ClientRect: TRect;
- begin
- GetClientRect(HWindow, ClientRect);
- with ClientRect do
- Scroller^.SetRange(Width - (Right - Left),
- Height - (Bottom - Top));
- Scroller^.ScrollTo(0, 0);
- InvalidateRect(HWindow, nil, true)
- end;
-
- {- Respond to changes in window size }
- procedure PAbortWindow.WMSize(var Msg: TMessage);
- begin
- TWindow.WMSize(Msg);
- if not (Msg.WParam = sizeIconic) then
- AdjustScroller
- end;
-
- {- Paint bitmap inside window }
- procedure PAbortWindow.Paint(PaintDC: HDC;
- var PaintInfo: TPaintStruct);
- var
- MemDC: HDC;
- OldBitmap: HBitmap;
- begin
- TWindow.Paint(PaintDC, PaintInfo);
- if Bitmap <> 0 then
- begin
- MemDC := CreateCompatibleDC(PaintDC);
- OldBitmap := SelectObject(MemDC, Bitmap);
- BitBlt(PaintDC, 0, 0, Width, Height, MemDC, 0, 0, SRCCopy);
- SelectObject(MemDC, OldBitmap);
- DeleteDC(MemDC)
- end
- end;
-
- {- Execute Menu:Print command }
- procedure PAbortWindow.CMPrint(var Msg: TMessage);
- var
- DC, MemDC: HDC;
- OldBitmap: HBitmap;
- begin
- if (Bitmap <> 0) and PrnStart('PAbort') then
- begin
- DC := GetDC(HWindow);
- MemDC := CreateCompatibleDC(DC);
- ReleaseDC(HWindow, DC);
- OldBitmap := SelectObject(MemDC, Bitmap);
- BitBlt(PDc, 0, 0, Width, Height, MemDC, 0, 0, SRCCopy);
- NewPage;
- PrnStop;
- SetFocus(HWindow);
- SelectObject(MemDC, OldBitmap);
- DeleteDC(MemDC)
- end
- end;
-
- {- Execute Menu:Exit command }
- procedure PAbortWindow.CMQuit(var Msg: TMessage);
- begin
- CloseWindow
- end;
-
- var
-
- PAbortApp: PAbortApplication;
-
- begin
- PAbortApp.Init('PAbortApp');
- PAbortApp.Run;
- PAbortApp.Done
- end.
-
-
- {--------------------------------------------------------------
- Copyright (c) 1991 by Tom Swan. All rights reserved.
- Revision 1.00 Date: 5/17/1991
- ---------------------------------------------------------------}
-